package com.tourism.storage.dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.t2cn.common.dbwrap.DbWrapException;
import com.t2cn.common.dbwrap.Jdbc;
import com.tourism.storage.ConnextionProxy;
import com.tourism.storage.pojo.Partner;

public class PartnerDao {
	public int addPartner(Partner pojo){
		Connection conn = null;
		try {
			conn = ConnextionProxy.getTestConnection();
			int i = Jdbc.Insert.insert(conn, pojo);
			conn.commit();
			return i;
		} catch (DbWrapException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			Jdbc.Resource.closeConnection(conn);
		}
		return 0;
	}
	public int updatePartner(Partner pojo){
		Connection conn = null;
		try {
			conn = ConnextionProxy.getTestConnection();
			Partner where = new Partner();
			where.setPartnerid(pojo.getPartnerid());
			int i = Jdbc.Update.update(conn, pojo, where);
			conn.commit();
			return i;
		} catch (DbWrapException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			Jdbc.Resource.closeConnection(conn);
		}
		return 0;
	}
	public List<Partner> getPartbers(Integer status){
		Connection conn = null;
		try {
			conn = ConnextionProxy.getTestConnection();
			Partner pojo = new Partner();
			pojo.setStatus(status);
			List<Partner> list = Jdbc.Select.select(conn, pojo);
			return list;
		} catch (DbWrapException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			Jdbc.Resource.closeConnection(conn);
		}
		return null;
	}
	public Partner getPartberById(Integer partnerid){
		Connection conn = null;
		try {
			conn = ConnextionProxy.getTestConnection();
			Partner pojo = new Partner();
			pojo.setPartnerid(partnerid);
			List<Partner> list = Jdbc.Select.select(conn, pojo);
			return (Partner)Jdbc.Select.getFirstNode(list);
		} catch (DbWrapException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			Jdbc.Resource.closeConnection(conn);
		}
		return null;
	}
}
